package hiho.ku._1015;

import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		for (int i = 0; i < n; i++)
			run(in);
	}
	
	private static void run(Scanner in) {
		String o = in.next();
		String s = in.next();
		
		int[] m = new int[o.length() + 1];
		m[0] = -1;
		for (int i = 1; i <= o.length(); i++) {
			char now = o.charAt(i - 1);
			int find = m[i - 1];
			while (find >= 0 && o.charAt(find) != now)
				find = m[find];
			m[i] = find + 1;
		}
		
		int[] f = new int[s.length() + 1];
		f[0] = 0;
		for (int i = 1; i <= s.length(); i++) {
			char now = s.charAt(i - 1);
			int find = f[i - 1];
			while (find >= 0 && (find >= o.length() || o.charAt(find) != now))
				find = m[find];
			f[i] = find + 1;
		}
		
		
		int ans = 0;
		for (int i = 1; i <= s.length(); i++)
			if (f[i] == o.length())
				ans++;
		System.out.println(ans);
	}
}
